SET NOCOUNT ON;
declare @version smallint = 2;
declare @release smallint = 1;
declare @script_name varchar(256)
set @script_name='UtilityDB_V'+convert(varchar(5),@version)+'R'
	+right('00000'+convert(varchar(5),@release),5)+'.sql'

if exists (select 1 from dbo.database_version_information where script_name=@script_name and undone=0)
	print 'script '+@script_name+' already executed, please undo then re-execute.';
else
begin try
begin tran
/*--Begin Code Here --*/

create table udb.io_file_stats (
record_date datetime not null			/*Date and time at which the record was written*/
,database_id smallint not null
,file_id smallint not null
,num_of_reads bigint not null			/*Number of reads issued on the file.*/
,num_of_bytes_read bigint not null		/*Total number of bytes read on this file.*/
,io_stall_read_ms bigint not null		/*Total time, in milliseconds, that the users waited for reads issued on the file.*/
,num_of_writes bigint not null			/*Number of writes made on this file.*/
,num_of_bytes_written bigint not null	/*Total number of bytes written to the file.*/
,io_stall_write_ms bigint not null		/*Total time, in milliseconds, that users waited for writes to be completed on the file.*/
,io_stall bigint not null				/*Total time, in milliseconds, that users waited for I/O to be completed on the file.*/
,size_on_disk_bytes bigint not null		/*Number of bytes used on the disk for this file. For sparse files, this number is the actual number of bytes on the disk that are used for database snapshots.*/
,constraint PK_udb__io_file_stat primary key(record_date,database_id,file_id)
);













/*--End Code Here --*/
if exists (select 1 from dbo.database_version_information where script_name=@script_name and undone=1)
	update dbo.database_version_information 
	set undone=0
	,date_released=getdate()
	where
	script_name=@script_name;
else
	insert into dbo.database_version_information 
	values(@script_name,@version,@release,GETDATE(),0);


print 'script '+@script_name+' succeeded!'
commit tran
end try
begin catch 
	declare @error_message varchar(2000);
	set @error_message='SCRIPT:'+@script_name+' FAILED! ROLLBACK!  ERROR_MESSAGE:'+coalesce(error_message(),'')+' ERROR_NUMBER:'+coalesce(convert(varchar(10),error_number()),'')
	ROLLBACK
	raiserror(@error_message,16,1)
end catch